package com.smart_campus.stat.service.impl;

import com.smart_campus.stat.mapper.StatMapper;
import com.smart_campus.stat.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Alfred
 * @date 2020/6/16 20:20
 */
@Service
public class statServiceImpl implements StatService {

    @Autowired
    private StatMapper statMapper;

    @Override
    public List<Double> loadBrowsethestatisticalJson(String year) {
        return this.statMapper.loadBrowsethestatisticalJson(year);
    }

    @Override
    public List userRegistrationStat(String year) {
        List list=new ArrayList();
        for (int i=1;i<=12;i++){
            String ym="";
            if (i<10){
                ym=year+"0"+i;
            }else {
                ym=year+i;
            }
            list.add(statMapper.userRegistrationStat(ym));
        }

        return list;
    }

    @Override
    public List<String> Userlocationinformation(String year) {
        List list2=new ArrayList();
        List list3=new ArrayList();//男
        List list4=new ArrayList();//女
        List<String> list=statMapper.Userlocationinformation();
        List<Map> list1=statMapper.Userlocationinformation1(year);
        for (String area:list) {
            int i=0;
            int o=0;
            for (Map map:list1){
                if (area.equals(map.get("site"))&& map.get("user_sex").equals("1")){
                    list3.add(map.get("sum1"));
                    i++;
                }else if(area.equals(map.get("site"))&& map.get("user_sex").equals("0")){
                    list4.add(map.get("sum1"));
                    o++;
                }
            }
            if(i==0){
                list3.add(0);
            }else if(o==0){
                list4.add(0);
            }else if(i==0&&o==0){
                list4.add(0);
                list3.add(0);
            }
        }
        list2.add(list);
        list2.add(list3);
        list2.add(list4);
        return list2;
    }
}
